#include <bits/stdc++.h>
using namespace std;
int main() {
  int tc;
  cin >> tc;
  while (tc--) {
    string s;
    cin >> s;
    int n;
    cin >> n;
    vector<int> b(n);
    for (int i = 0; i < n; ++i) cin >> b[i];
    vector<vector<int>> groups;
    while (true) {
      vector<int> pos;
      for (int i = 0; i < n; ++i)
        if (b[i] == 0) pos.push_back(i);
      if (pos.empty()) break;  // 无字母可用
      groups.push_back(pos);
      for (int i = 0; i < n; ++i) {
        if (b[i] == 0)
          b[i] = 0x3f3f3f3f;
        else
          for (int pp : pos) b[i] -= abs(i - pp);
      }
    }
    map<char, int> cnts;
    for (int i = 0; i < s.size(); ++i) cnts[s[i]]++;
    string t(n, '?');
    auto j = cnts.rbegin();  // 从最大的字母开始
    for (auto g : groups) {
      while (j->second < g.size()) j++;  // 字母不够j个
      for (int pp : g) {
        t[pp] = j->first;  // 字母是j->second不会错，补齐
      }
      j++;
    }
    cout << t << endl;
  }
}
